
{% extends "zato/index.html" %}

{% block html_title %}Pub/sub message : {{ msg_id }}{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
{% endblock %}

{% block "extra_js" %}

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.form.js"></script>

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/pubsub/message-details.js"></script>

{% endblock %}

{% block "content" %}

{% if not has_msg %}

<div id="user-message-div"><pre id="user-message" class="user-message user-message-failure">Could not read message `{{ msg_id }}` from {{ object_type }} `{{ object_name }}`</pre></div>

{% else %}
<h2 class="zato">Pub/sub message : {{ msg_id }}

<div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

<div id="markup">
    <form novalidate id="message-details-form" action="<invalid>" method="post">
        <table id="data-table">
            <tr>
                <td class='inline_header' style="width:80px">
                    {% if object_type == "topic" %}
                        Topic
                    {% else %}
                        Queue for topic
                    {% endif %}
                </td>
                <td style="width:140px">
                    {% if object_type == "topic" %}
                        <a href="{% url "pubsub-topic" %}?cluster={{ cluster_id }}&amp;query={{ object_name }}">{{ object_name }}</a>
                    {% else %}
                        <a href="{% url "pubsub-endpoint-queues" cluster_id endpoint_id object_name_slug %}?query={{ object_name }}">{{ object_name }}</a>
                        {% if ws_ext_client_id %}
                            <span class="form_hint">{{ ws_ext_client_id }}</span>
                        {% endif %}
                    {% endif %}
                </td>

                <td class='inline_header' style="width:90px">
                    Publisher
                </td>
                <td style="width:170px">
                    {{ pub_endpoint_html|safe }}
                    {{ pub_pattern_matched }}
                </td>

                <td class='inline_header' style="width:90px">Priority <span class="form_hint">(1-9, 1=min)</span></td>
                <td>
                    {% if object_type == "topic" %}
                        {{ form.priority }}
                    {% else %}
                        {{ priority }}
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td class='inline_header' style="width:80px">
                    {% if object_type == "topic" %}
                        Pub time
                    {% else %}
                        Recv time
                    {% endif %}
                </td>
                <td style="width:120px">
                    {% if action == "publish" %}
                        <span class='form_hint'>---</span>
                    {% else %}
                        {% if object_type == "topic" %}
                            <a
                                id="a_pub_time"
                                href="javascript:$.fn.zato.toggle_time('pub_time', '{{ pub_time }}', '{{ pub_time_utc }}')">{{ pub_time }}
                            </a>
                        {% else %}
                            <a
                                id="a_recv_time"
                                href="javascript:$.fn.zato.toggle_time('recv_time', '{{ recv_time }}', '{{ recv_time_utc }}')">{{ recv_time }}
                            </a>
                        {% endif %}
                    {% endif %}
                </td>


                <td class='inline_header' style="width:90px">
                    {% if object_type == "topic" %}
                        Ext. pub time
                    {% else %}
                        Subscriber
                    {% endif %}
                </td>
                <td style="width:170px">
                    {% if object_type == "topic" %}
                        {% if ext_pub_time %}
                        <a
                            id="a_ext_pub_time"
                            href="javascript:$.fn.zato.toggle_time('ext_pub_time', '{{ ext_pub_time }}', '{{ ext_pub_time_utc }}')">{{ ext_pub_time }}
                        </a>
                        {% else %}
                            <span class='form_hint'>---</span>
                        {% endif %}
                    {% else %}
                        {{ sub_endpoint_html|safe }}
                        {{ sub_pattern_matched }}
                    {% endif %}

                </td>

                <td class='inline_header' style="width:90px">Pub ext. client ID</td>
                <td style="width:140px">{{ ext_client_id|default:"<span class='form_hint'>---</span>" }}</td>
            </tr>
            <tr>
                <td class='inline_header' style="width:80px">Msg ID</td>
                <td style="width:120px">{% if action == "publish" %}<span class='form_hint'>---</span>{% else %}{{ msg_id }}{% endif %}</td>

                <td class='inline_header' style="width:90px">Expiration <span class="form_hint">(in s)</span></td>
                <td style="width:170px">
                    {% if object_type == "topic" %}
                        {{ form.expiration }}
                        {{ form.exp_from_now }} <label for="id_exp_from_now">From now</label>
                    {% else %}
                        {{ expiration }}
                    {% endif %}
                </td>

                <td class='inline_header' style="width:90px">Service</td>
                <td style="width:140px">
                    {% if hook_pub_service_name %}
                        <a href="{% url "service-overview" hook_pub_service_name %}?cluster={{ cluster_id }}">{{ hook_pub_service_name }}</a>
                    {% else %}
                        <span class='form_hint'>---</span>
                    {% endif %}
                </td>

            </tr>
            <tr>
                <td class='inline_header' style="width:80px">Correl ID</td>
                <td style="width:120px">
                    {% if object_type == "topic" %}
                        {{ form.correl_id }}
                    {% else %}
                        {{ correl_id|default:"<span class='form_hint'>---</span>" }}
                    {% endif %}
                </td>

                <td class='inline_header' style="width:90px">Expiration time</td>
                <td style="width:170px" id="expiration_time">
                    {% if expiration_time %}
                        <a
                            id="a_expiration_time"
                            href="javascript:$.fn.zato.toggle_time('expiration_time', '{{ expiration_time }}', '{{ expiration_time_utc }}')">{{ expiration_time }}
                        </a>
                    {% else %}
                        <span class='form_hint'>---</span>
                    {% endif %}
                </td>


                <td class='inline_header' style="width:90px">
                    GD
                </td>
                <td style="width:140px">
                    {{ has_gd|yesno:"Yes,No" }}
                </td>

            </tr>
            <tr>
                <td class='inline_header' style="width:80px">In reply to</td>
                <td style="width:120px">
                    {% if object_type == "topic" %}
                        {{ form.in_reply_to }}
                    {% else %}
                        {{ in_reply_to|default:"<span class='form_hint'>---</span>" }}
                    {% endif %}
                </td>

                <td class='inline_header' style="width:90px">Size <span class='form_hint'>(in bytes)</span></td>
                <td style="width:170px" id="size">{% if action == "publish" %}<span class='form_hint'>---</span>{% else %}{{ size }}{% endif %}</td>

                <td class='inline_header' style="width:90px">
                    {% if not has_gd %}Server{% endif %}
                </td>
                <td style="width:140px">
                    {% if not has_gd %}{{ server_name }}:{{ server_pid }}{% endif %}
                </td>
            </tr>
            <tr>
            <tr>
                <td class='inline_header' colspan="6">
                    {% if object_type == "queue" %}
                        Data in queue
                    {% else %}
                        Data in topic
                    {% endif %}
                    ↓
                </td>
            </tr>
            <tr>
                <td colspan="6"><textarea style="height:200px" id="data-textarea" name="data">{{ data }}</textarea></td>
            </tr>
            {% if object_type == "topic" %}
            <tr>
                <td colspan="6" style="text-align:right">
                    <input type="submit" name="update-message-button" value="Update message in {{ object_type }}" />
                </td>

                {% if object_type == "topic" %}
                    {{ form.mime_type }}
                {% endif %}

                <input type="hidden" name="msg_id" id="msg_id" value="{{ msg_id }}" />
                <input type="hidden" name="has_gd" id="has_gd" value="{{ has_gd }}" />
                <input type="hidden" name="server_name" id="server_name" value="{{ server_name }}" />
                <input type="hidden" name="server_pid" id="server_pid" value="{{ server_pid }}" />
                <input type="hidden" name="cluster_id" id="cluster_id" value="{{ cluster_id }}" />
            </tr>
            {% endif %}
        </table>
    </form>
</div>

{% endif %}

{% endblock %}
